<?php
namespace app\admin\controller;

use think\Controller;
use think\facade\Session;
class Base extends Controller
{
    public function initialize()
    {
        //接受参数
        $this->param = $this->request->param();
        //连接redis
        $this->redis = new \Redis();
        $this->redis->connect('127.0.0.1', 6379);
        $res =  $this->redis->ping(); // 检测当前链接状态，返回PONG或者抛出异常。
        //调用模型
        $this->UserInfoModel = model('user_info'); //用户信息表
        $this->AdminUserModel = model('admin_user'); //管理员表
        $this->SideNavModel = model('side_nav'); //侧边栏导航
    }
    public function createOrderNo(){ 
        $houseNum = time()-strtotime(date('Y-m-d',time()));
        $time = date('ymd');
        $length = 20;
        $prefixTime = $time.$houseNum;
        $lastLen = $length - strlen($prefixTime);
        $utimestamp = microtime(true);
        $timestamp = floor($utimestamp);
        $milliseconds = round(($utimestamp - $timestamp) * 1000000);
        $orderNo = $prefixTime.$milliseconds;
        if($lastLen-strlen($milliseconds)>0){
            for($i=0;$i<($lastLen-strlen($milliseconds));$i++){
                $orderNo .= rand(1,9);
            }
        }
        return $orderNo;
    }
}
